home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kshred.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  4.7 KB  |  157 lines

  1. /*--------------------------------------------------------------------------*
  2.  KShred.h  Copyright (c) 2000 MieTerra LLC.
  3.  Credits:  Andreas F. Pour <bugs@mieterra.com> 
  4.  
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11.  
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14.  
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  18. AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  19. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22.  
  23. #ifndef kshred_h
  24. #define kshred_h
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <unistd.h>
  30. #include <qstring.h>
  31. #include <qfile.h>
  32. #include <qobject.h>
  33.  
  34. #include <kio/global.h>
  35.  
  36. /**
  37.  * @deprecated
  38.  * Erase a file in a way that makes recovery impossible -- well, no guarentee
  39.  * of that, but at least as difficult as reasonably possible.
  40.  * For this, KShred write several times over the
  41.  * existing file, using different patterns, before deleting it.
  42.  * @author Andreas F. Pour <bugs@mieterra.com>
  43.  * @author David Faure <faure@kde.org> (integration into KDE and progress signal)
  44.  */
  45. class KIO_EXPORT_DEPRECATED KShred : public QObject { // KDE4: remove
  46.  
  47.   Q_OBJECT
  48.  
  49.     public:
  50.  
  51.     /**
  52.      * Initialize the class using the name of the file to 'shred'.
  53.      * @param fileName fully qualified name of the file to shred.
  54.      */
  55.         KShred(QString fileName);
  56.  
  57.     /*
  58.      * Destructor for the class.
  59.      */
  60.         ~KShred();
  61.  
  62.     /**
  63.      * Writes all 1's over the entire file and flushes the file buffers.
  64.      * @return true on success, false on error (invalid filename or write error)
  65.      */
  66.  
  67.         bool fill1s();
  68.     /**
  69.      * Writes all 0's over the entire file and flushes the file buffers.
  70.      * @return true on success, false on error (invalid filename or write error)
  71.      */
  72.         bool fill0s();
  73.  
  74.     /**
  75.      * Writes the specified byte over the entire file and flushes the file buffers.
  76.      * @param byte the value to write over every byte of the file
  77.      * @return true on success, false on error (invalid filename or write error)
  78.      */
  79.         bool fillbyte(unsigned int byte);
  80.  
  81.     /**
  82.      * Writes random bites over the entire file and flushes the file buffers.
  83.      * @return true on success, false on error (invalid filename or write error)
  84.      */
  85.         bool fillrandom();
  86.  
  87.     /**
  88.      * Writes the specified byte array over the entire file and flushes the file buffers.
  89.      * @param pattern the value to write over the entire file
  90.      * @param size the length of the 'pattern' byte array
  91.      * @return true on success, false on error (invalid filename or write error)
  92.      */
  93.         bool fillpattern(unsigned char *pattern, unsigned int size);
  94.  
  95.     /**
  96.      * Shreds a file by writing a series of values over it (uses 
  97.      * #fill0s, then fill1s, then fillrandom, then
  98.          * fillbyte with 0101..., then fillbyte with 1010....
  99.      * @return true on success, false on error (invalid filename or write error)
  100.          */
  101.         bool shred();
  102.  
  103.         /**
  104.          * The simplest method to shred a file.
  105.          * No need to create an instance of the class.
  106.      * @param fileName fully qualified name of the file to shred.
  107.          */
  108.         static bool shred(QString fileName);
  109.  
  110.     signals:
  111.         /**
  112.          * Shows progress of the shredding.
  113.      * @param bytes the number of bytes written to the file
  114.          */
  115.         void processedSize(KIO::filesize_t bytes);
  116.  
  117.         /**
  118.          * Shows a message in the progress dialog
  119.      * @param message the message to display
  120.          */
  121.         void infoMessage(const QString & message);
  122.  
  123.     private:
  124.     /**
  125.      * @internal write the data to the file
  126.      */
  127.         bool writeData(unsigned char *data, unsigned int size);
  128.  
  129.     /**
  130.      * @internal flush the data to the file
  131.      */
  132.         bool flush();
  133.  
  134.     /**
  135.      * @internal structure for the file information
  136.      */
  137.         QFile *file;
  138.  
  139.     /**
  140.      * @internal for the size of the file
  141.      */
  142.         KIO::filesize_t fileSize;
  143.  
  144.     /**
  145.      * @internal for keeping track of progress
  146.      */
  147.         unsigned int totalBytes;
  148.         unsigned int bytesWritten;
  149.         unsigned int lastSignalled;
  150.         unsigned int tbpc;
  151.         unsigned int fspc;
  152.     private:
  153.     class KShredPrivate* d;
  154. };
  155.  
  156. #endif
  157.